package Common
{
	public class RoleConfig
	{
		public var roleObject:Object = null;
		
		public function RoleConfig()
		{
			
		}
		
		public static var instance:RoleConfig = null;	
		public static function Instance():RoleConfig
		{
			if ( instance == null )
			{
				instance = new RoleConfig();
			}
			
			return instance;
		}
		
		
		public function getIndex( role:int , color:int , ride:int ):int
		{
			if ( ride == GameDefine.INVALIDID )
			{
				return roleObject[ role ][ color ].role;
			}
			else
			{
				if ( ride == 10 )
				{
					return roleObject[ role ][ color ].dragon;
				}
				else if ( ride == 11 )
				{
					return roleObject[ role ][ color ].tiger;
				}
				else
				{
					return roleObject[ role ].ride[ ride ];
				}
			}
		}
		
		
		public function init( xml:XML ):void
		{
			roleObject = new Object();
			
			for each ( var element:XML in xml.elements() )
			{
				var id:int = element.@id;
				roleObject[ id ] = new Object();
				roleObject[ id ].ride = new Object();
				roleObject[ id ].ride[ 0 ] = int( element.@r0 );
				roleObject[ id ].ride[ 1 ] = int( element.@r1 );
				roleObject[ id ].ride[ 2 ] = int( element.@r2 );
				roleObject[ id ].ride[ 3 ] = int( element.@r3 );
				roleObject[ id ].ride[ 4 ] = int( element.@r4 );
				roleObject[ id ].ride[ 5 ] = int( element.@r5 );
				roleObject[ id ].ride[ 6 ] = int( element.@r6 );
				roleObject[ id ].ride[ 7 ] = int( element.@r7 );
				roleObject[ id ].ride[ 8 ] = int( element.@r8 );
				roleObject[ id ].ride[ 9 ] = int( element.@r9 );
				
				for each ( var e:XML in element.elements() )
				{
					var c:int = e.@c;
					roleObject[ id ][ c ] = new Object();
					
					roleObject[ id ][ c ].role = int( e.@r );
					roleObject[ id ][ c ].dragon = int( e.@r0 );
					roleObject[ id ][ c ].tiger = int( e.@r1 );
				}
			}
			
			xml = null;
		}
		
		
	}
	
}
